from typing import List, Dict, Any, Optional
from qwen3_agent_function_calling.tools.Tool import Tool

class WeatherTool(Tool):
    """天气查询工具"""

    def get_name(self) -> str:
        return "weather"

    def get_description(self) -> str:
        return "查询指定城市天气，需传入城市名称参数"

    def get_parameters(self) -> Dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string",
                    "description": "中国城市名称",
                    "examples": ["北京", "上海", "广州"]
                }
            },
            "required": ["city"],
        }

    def execute(self, arguments: Dict[str, Any]) -> str:
        city = arguments.get("city", "").strip()
        if not city:
            return "错误：请提供城市名称（如'北京'）"

        # 模拟天气数据
        weather_data = {
            "北京": "晴朗，25°C，微风",
            "上海": "多云，28°C，东风3级",
            "广州": "小雨，30°C，南风2级",
            "深圳": "阴天，27°C，无风"
        }
        return f"{city}当前天气：{weather_data.get(city, '暂未获取到该城市天气')}"
